Rails helper module undefined method `sort'

Posted by Magicked on Stack Overflow See other posts from Stack Overflow or by Magicked
Published on 2010-04-12T16:16:27Z Indexed on 2010/04/12 16:23 UTC
Read the original article Hit count: 290

Filed under:
|

I'm trying to create a simple helper module in rails, and I'm stumped on the following error message from my new person form (app/views/people/new.html.erb):

undefined method `sort' for 97:Fixnum

Extracted source (around line #17):

14:   <p>
15:         <% nations = { 'United States of America' => 'USA', 'Canada' => 'Canada', 'Mexico' => 'Mexico', 'United Kingdom' => 'UK' } %>
16:     <%= f.label :country %><br />
17:         <%= radio_buttons(:person, :country, nations) %>
18:         
19:   </p>
20:   <p>

radio_buttons is a helper module I have created for my view. Here it is (app/helpers/people_helper.rb):

module PeopleHelper 

def radio_buttons(model_name, target_property, button_source) 
  html='' 
  list = button_source.sort 
  list.each do |x| 
    html << radio_buttons(model_name, target_property, x[1]) 
    html << h(x[0]) 
    html << '<br />' 
  end 
  return html 
end 

end

The problem appears to be on the "list = button_source.sort", but I'm not sure why it says the method is undefined. I have been able to use it directly within my view code. Am I not able to use methods like this within helper modules? Do I need to include something?

Thanks for any help!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby